let obj = {
  name: "xjh",
  age: 10,
};

function objNameFn1() {
  console.log("objNameFn1");
}
function objNameFn2() {
  console.log("objNameFn2");
}
function objAgeFn1() {
  console.log("objAgeFn1");
}
function objAgeFn2() {
  console.log("objAgeFn2");
}

// 创建weakMap
const weakMap = new WeakMap();

// 依赖收集
const objMap = new Map();
objMap.set("name", [objNameFn1, objNameFn2]);
objMap.set("age", [objAgeFn1, objAgeFn2]);
weakMap.set(obj1, objMap);

// 发生变化
obj.name = "xjh2";

// 取出数据
const targetMap = weakMap.get(obj);
const fns = targetMap.get("name");

// 依次执行
fns.forEach((fn) => {
  fn();
});
